﻿using mal.WP7.Framework.Controls;
using mal.WP7.StopwatchTimer.ViewModels;

namespace mal.WP7.StopwatchTimer.Views
{
    public partial class StopwatchView : NavigatePhoneApplicationPage
    {
        private StopwatchViewModel viewModel;

        public StopwatchView()
        {
            InitializeComponent();

            viewModel = new StopwatchViewModel();
            this.DataContext = viewModel;

            viewModel.Laps.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Laps_CollectionChanged);
        }

        void Laps_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (viewModel.Laps.Count > 0)
            {
                laps.ScrollIntoView(viewModel.Laps[viewModel.Laps.Count - 1]);
            }
        }
    }
}